package de.hft_stuttgart.dsa.ctt.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Eduard Tudenhoefner
 */
public class Course implements Comparable<Course> {
	private String courseId;
	private String teacher;
	private int numberOfLectures;
	private int minWorkingDays;
	private int numberOfStudents;
	private boolean asDoubleLecture;
	private List<UnavailabilityConstraint> unavailabilityConstraints = new ArrayList<UnavailabilityConstraint>();
	private List<Curriculum> curriculums = new ArrayList<Curriculum>();
	
	public Course() {

	}

	public Course(String courseLine) {
		String[] courseSpecification = courseLine.split(" ");
		setCourseId(courseSpecification[0]);
		setTeacher(courseSpecification[1]);
		setNumberOfLectures(Integer.parseInt(courseSpecification[2]));
		setMinWorkingDays(Integer.parseInt(courseSpecification[3]));
		setNumberOfStudents(Integer.parseInt(courseSpecification[4]));
	}

	public void addUnavailabilityConstraint(UnavailabilityConstraint constraint) {
		unavailabilityConstraints.add(constraint);
	}

	public String getCourseId() {
		return courseId;
	}

	public void setCourseId(String courseId) {
		this.courseId = courseId;
	}

	public String getTeacher() {
		return teacher;
	}

	public void setTeacher(String teacher) {
		this.teacher = teacher;
	}

	public int getNumberOfLectures() {
		return numberOfLectures;
	}

	public void setNumberOfLectures(int numberOfLectures) {
		this.numberOfLectures = numberOfLectures;
	}

	public int getMinWorkingDays() {
		return minWorkingDays;
	}

	public void setMinWorkingDays(int minWorkingDays) {
		this.minWorkingDays = minWorkingDays;
	}

	public int getNumberOfStudents() {
		return numberOfStudents;
	}

	public void setNumberOfStudents(int numberOfStudents) {
		this.numberOfStudents = numberOfStudents;
	}

	public boolean isAsDoubleLecture() {
		return asDoubleLecture;
	}

	public void setAsDoubleLecture(boolean asDoubleLecture) {
		this.asDoubleLecture = asDoubleLecture;
	}

	public List<UnavailabilityConstraint> getUnavailabilityConstraints() {
		return unavailabilityConstraints;
	}

	public void setUnavailabilityConstraints(List<UnavailabilityConstraint> unavailabilityConstraints) {
		this.unavailabilityConstraints = unavailabilityConstraints;
	}
	
	public List<Curriculum> getCurriculums() {
		return curriculums;
	}

	public void setCurriculums(List<Curriculum> curriculums) {
		this.curriculums = curriculums;
	}

	/**
	 * @return The priority of this course based on defined unavailability
	 *         constraints. If a course doesn't have any unavailability
	 *         constraints, 1 is returned in order to avoid zero values.
	 */
	public int getPriority() {
		if (null != unavailabilityConstraints && !unavailabilityConstraints.isEmpty()) {
			return unavailabilityConstraints.size() + 1;
		}
		return 1;
	}

	/**
	 * @see Comparable#compareTo(Object)
	 * 
	 * Compares a course with this course.
	 * 
	 * @return Positive value if this object has more constraints than the received one and vice versa.
	 */
	@Override
	public int compareTo(Course course) {
		return getPriority() - course.getPriority();
	}

	/**
	 * Compares a course with this course.
	 * 
	 * @return Positive value if this object has less number of students than the received one and vice versa.
	 */
	public int compareStudentNumbers(Course course) {
		return course.getNumberOfStudents() - numberOfStudents;
	}
	
	@Override
	public String toString() {
		return "Course [courseId=" + courseId + "]";
	}

}